package LocalStorage

import (
	"KumquatDrivesServices/StorageEngine"
	"KumquatDrivesServices/global"
	"KumquatDrivesServices/model"
	"github.com/google/uuid"
	"github.com/sirupsen/logrus"
	"path/filepath"
	"strings"
)

const ext = ".tmp" // 固定扩展名

type LocalEngine struct {
}

func (LocalEngine) InitiateMultipartUpload(userId model.SnowflakeIdType) StorageEngine.EngineID {
	str := StorageEngine.EngineID(strings.ReplaceAll(uuid.New().String(), "-", ""))
	if err := str.SetTempFileSize(userId, 0); err != nil {
		logrus.Errorf("Error while setting temp file size for user %d: %v", userId, err)
	}
	return str
}
func (LocalEngine) getFilePath() string {
	return filepath.Join(global.Config.LocalStorage.UploadPath, "file")
}
func (Le LocalEngine) getTmpFilePath(uploadId StorageEngine.EngineID) string {
	return filepath.Join(Le.getFilePath(), "tmp", uploadId.String())
}
func (Le LocalEngine) getCoverFilePath(userEmail string) string {
	return filepath.Join(Le.getFilePath(), userEmail, "cover")
}
